package com.yunqiao.api.controller;

import java.util.Map;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import springfox.documentation.annotations.ApiIgnore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.yunqiao.api.annotation.Login;
import com.yunqiao.common.exception.CustomApiException;
import com.yunqiao.common.validator.ValidatorUtils;
import com.yunqiao.common.utils.ApiResponse;
import com.yunqiao.service.api.entity.DistrictPriceEntity;
import com.yunqiao.service.api.DistrictPriceService;
import com.yunqiao.common.utils.PageUtils;


/**
 * 区域  代理费    定金
 * @author Crocutax
 * @email wangxw725@163.com
 * @date 2019-03-08 17:44:10
 */
@RestController
@RequestMapping("api/districtprice")
@Api(tags = " districtPriceApiController" ,description = "区域  代理费    定金管理")
public class  districtPriceApiController {

    @Autowired
    private DistrictPriceService districtPriceService;

    /**
     * 列表
     */
    @ApiImplicitParams({
        @ApiImplicitParam(name = "page", value = "页码", required = false ,defaultValue = "1",paramType = "query" , dataType = "int"),
        @ApiImplicitParam(name = "limit", value = "数量", required = false,defaultValue = "10",paramType = "query" , dataType = "int")
    })
    @GetMapping("/list")
    @ApiOperation("查询区域  代理费    定金列表")
    public ApiResponse<PageUtils<DistrictPriceEntity>> list(@ApiIgnore @RequestParam Map<String, Object> params){
        PageUtils page =  districtPriceService.queryPage(params);
        return new ApiResponse<>(page);
    }

    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @ApiOperation("查询单个区域  代理费    定金")
    public ApiResponse<DistrictPriceEntity> info(@PathVariable("id") Long id){
        if (id == null) {
            throw new CustomApiException("ID不能为空");
        }
         DistrictPriceEntity districtPrice =  districtPriceService.getById(id);
        return new ApiResponse<>( districtPrice);
    }

    /**
     * 保存
     */
    @Login
    @PostMapping("/save")
    @ApiOperation("保存区域  代理费    定金")
    public ApiResponse save( DistrictPriceEntity districtPrice){
        ValidatorUtils.validateEntity( districtPrice);
         districtPriceService.save( districtPrice);
        return new ApiResponse<>();
    }

    /**
     * 修改
     */
    @Login
    @PutMapping("/update/{id}")
    @ApiOperation("修改区域  代理费    定金")
    public ApiResponse update(@PathVariable Long id ,  DistrictPriceEntity districtPrice){
         DistrictPriceEntity dbItem =  districtPriceService.getById(id);
        if(dbItem==null){
            throw new CustomApiException("ID有误, 未找到对应数据");
        }
         districtPriceService.updateById( districtPrice);
        return new ApiResponse<>();
    }

    /**
     * 删除
     */
    @Login
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除区域  代理费    定金")
    public ApiResponse delete(@PathVariable Long id){
        if (id == null) {
            throw new CustomApiException("ID不能为空");
        }
         districtPriceService.removeById(id);
        return new ApiResponse<>();
    }



}
